package cn.gok.service.impl;

import cn.gok.bo.MaintainDormitoryBO;
import cn.gok.dao.MaintainDao;
import cn.gok.entity.TMaintainDormitory;
import cn.gok.service.MaintainService;
import cn.gok.util.R;
import cn.gok.util.Sqlsessionutil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.session.SqlSession;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MaintainServiceImpl implements MaintainService {
    private SqlSession sqlSession;
   private MaintainDao maintainDao;

    public MaintainServiceImpl(){
        sqlSession = Sqlsessionutil.getSqlSessionFactory().openSession(true);
        maintainDao = sqlSession.getMapper(MaintainDao.class);
    }

    @Override
    public R addMaintain(TMaintainDormitory tMaintainDormitory) {
        return null;
    }

    @Override
    public R queryInfo(int stuId, int state, int currentPage, int pageSize) {
        //开启分页
         PageHelper.startPage(currentPage, pageSize);
        List<MaintainDormitoryBO> maintainDormitoryBOS = maintainDao.queryInfo(stuId, state);
        System.out.println("ssssss"+maintainDormitoryBOS);

        PageInfo pageInfo = new PageInfo(maintainDormitoryBOS);
        /*
        respData:{

        },
        datas{

        }

         */
        R r = new R<>();
        r.put("result",true);
        r.put("msg","");

        Map<String ,Object>pagination=new HashMap<>();
        pagination.put("currentPage",currentPage);
        pagination.put("pageSize",pageSize);
        pagination.put("total",pageInfo.getTotal());

        r.put("pagination",pagination);
        r.put("datas",maintainDormitoryBOS);
        return r;

    }


}
